<!doctype html>
<html  class="x-admin-sm">
<head>
  <meta charset="UTF-8">
  <title>软件研发项目合同规划系统</title>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="login-bg">

    <div class="login layui-anim layui-anim-up">
        <div class="message">软件研发项目合同规划系统</div>
        <div id="darkbannerwrap"></div>

        <form method="post" class="layui-form" >
            <input name="username" id="username" placeholder="用户名 (至少5个字符)"  type="text" required class="layui-input" lay-verify="nikename">
            <hr class="hr15">
            <input name="password" id="password" placeholder="密码 (6-12个字符)"  type="password" class="layui-input" required lay-verify="pass">
            <hr class="hr15">
            <input name="password2" id="password2" placeholder="确认密码"  type="password" class="layui-input" required lay-verify="repass">
            <hr class="hr15">
            <input value="注册" lay-submit lay-filter="register" style="width:100%;" type="submit">
            <hr class="hr20" >
        </form>
            <div style="float: right;">
              <a href="login.html"><cite>已有账号, 前去登录!</cite></a>
            </div>
    </div>
    <script>
        $(function  () {
            layui.use('form', function(){
              var form = layui.form;
              form.on('submit(register)', function(data){
                  console.log(JSON.stringify(data.field));
                  $.ajax({
                      url: "/user/register",
                      dateType: "json",
                      contentType : "application/json",
                      type: "post",
                      data: JSON.stringify(data.field),
                    success: function(res) {
                          res = JSON.parse(res);
                          if(res.msg == 'success') {
                              layer.msg("注册成功! 正在为您跳转页面");
                              setTimeout(
                                  function(){
                                      location.href='login.html';;
                                  },1500)
                          } else {
                            layer.msg('注册失败, 用户名已被注册');
                          }
                      }
                  })
                return false;
              });
            });
        })
    </script>
    <script>layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
            layer = layui.layer;

            //自定义验证规则
            form.verify({
                nikename: function(value) {
                    if (value.length < 5) {
                        return '昵称至少得5个字符啊';
                    }
                },
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                repass: function(value) {
                    if ($('#password').val() != $('#password2').val()) {
                        return '两次密码不一致';
                    }
                }
            });
        });</script>
</body>
</html>